import {
  GetConsumablesManagementInfo,
  GetContractInfo,
  GetEvectionInfo,
  GetExpenseAccountInfo,
  GetInfoPicture,
  GetInvoicInfo,
  GetIssueReceiptInfo,
  GetLeaveInfo,
  GetMeetingLogInfo,
  GetMeetingRoomInfo,
  GetOrderManagementInfo,
  GetPaymentFunctionInfo,
  GetPreviewImage,
  GetProcureApplicationInfo,
  GetProcurementConfirmationInfo,
  GetProjectArchivingInfo,
  GetSealInfo,
  GetTapeoutPaymengtInfo,
  GetTopicInfo,
  GetUserInfoById
} from "../../../../constData/requestFun/_httpRequest";
import {
  GetUserInfoFiled
} from "../../../../constData/requestFun/_utils";
import isEmpty from 'loadsh/isEmpty'
import {
  ChipPaymentStatusChange,
  ConsumableManagementStatusChange,
  ContractManagementStatusChange,
  EvectionStatusChange,
  GetApproveLog,
  GetChipPayment,
  GetchipPaymentAccount,
  GetConsumableManagement,
  GetContractManagement,
  GetContractManagementById,
  GetEvection,
  GetEvectionById,
  GetInvoicing,
  GetIssueReceipts,
  GetLeave,
  GetMeetingMinutes,
  GetOrder,
  GetOrderManagement,
  GetPayment,
  GetProcurementConfirmation,
  GetProjectManagement,
  GetPurchaseRequest,
  GetPurchaseRequestById,
  GetReimbursement,
  GetReimbursementById,
  GetSalaryInfo,
  GetTopic,
  GetTopicById,
  GetTopicContract,
  GetUserInfo,
  GetUseSeal,
  InvoicingStatusChange,
  IssueReceiptsStatusChange,
  LeaveStatusChange,
  MeetingMinutesStatusChange,
  OrderManagementStatusChange,
  PaymentStatusChange,
  ProcurementConfirmationStatusChange,
  ProjectManagementStatusChange,
  PurchaseRequestStatusChange,
  ReimbursementStatusChange,
  TopicStatusChange,
  UseSealStatusChange
} from "/constData/requestFun/_teseRequest";
import compact from 'loadsh/compact'
import {
  CORPID
} from "/constData/requestFun/_globalData";
import {
  GetUserNameById
} from "/constData/_";
Page({
  data: {
    CorpId: '',
    CheckType: '请假审核',
    LeaveInfo: [], //请假数据
    EvectionInfo: [], //出差数据
    PurchasedConfirmationInfo: [], //采购申请确认数据
    PurchasRequisitInfo: [], //采购申请数据
    SealInfo: [], //用印申请数据
    MeetronmInfo: [], //会议室申请数据
    ContractInfo: [], //合同管理
    TopicInfo: [], //议题申请
    MeetMinutesInfo: [], //会议纪要
    SalaryInfo: [], //薪资审批

    InvoicInfo: [], //开票数据
    IssueReceiptInfo: [], //开收据数据
    ExpenseAccountInfo: [], //报销数据
    PaymentFunctionInfo: [], //付款管理
    ProjectArchivingInfo: [], //项目管理
    TapoutBusinessInfo: [], //流片付款
    TapeoutIssuesContractsInfo: [], //流片议题和合同

    OrderManagementInfo: [], //订单管理
    ConsumablesManagementInfo: [], //耗材管理

    showLeave: true,
    showEvection: true,
    showPurchasedConfirmation: true,
    showPurchasRequisit: true,
    showSeal: true,
    showMeetronm: true,
    showTopic: true,
    showContract: true,
    showMeetMinutes: true,
    showSalary: true,

    showInvoic: true,
    showIssueReceipt: true,
    showExpenseAccount: true,
    showPaymentFunction: true,

    showProjectArchiving: true,
    showTapoutBusiness: true,
    showTapeoutIssuesContracts: true,

    showOrderManagement: true,
    showConsumablesManagement: true,

    BasicApplication: [{
      text: '请假审核',
      value: 'LeaveInfo'
    },
    {
      text: '出差审核',
      value: 'EvectionInfo'
    },
    ],
    SelectedValue: '',

    IntegratedAdministrationType: [{
      text: '采购申请',
      value: 'PurchasRequisitInfo'
    },
    {
      text: '采购确认',
      value: 'PurchasedConfirmationInfo'
    },
    {
      text: '用印申请',
      value: 'SealInfo'
    },
    {
      text: '议题申请',
      value: 'TopicInfo'
    },
    {
      text: '会议纪要',
      value: 'MeetMinutesInfo'
    },
    {
      text: '合同审批',
      value: 'ContractInfo'
    },
    {
      text: '薪资审批',
      value: 'SalaryInfo'
    },
    ],

    FinancialManagementType: [{
      text: '开票申请',
      value: 'InvoicInfo'
    },
    {
      text: '开收据申请',
      value: 'IssueReceiptInfo'
    },
    {
      text: '报销申请',
      value: 'ExpenseAccountInfo'
    },
    {
      text: '付款申请',
      value: 'PaymentFunctionInfo'
    },
    ],

    ProjectManagementType: [{
      text: '项目管理',
      value: 'ProjectArchivingInfo'
    },],

    TapeOutPaymentsType: [{
      text: '流片付款',
      value: 'TapoutBusinessInfo'
    },
    {
      text: '流片议题和合同',
      value: 'TapeoutIssuesContractsInfo'
    },
    ],

    LaboratoryType: [
      {
        text: '订单审批',
        value: 'OrderManagementInfo'
      },
      {
        text: '耗材审批',
        value: 'ConsumablesManagementInfo'
      },
    ],
    DisplayApproveName: []
  },
  TapeLaboratoryChange(value, items, e) {
    this.setData({
      SelectedValue: value ? value : this.data.SelectedValue
    })
    my.getStorage({
      key: 'userInfo',
      success: (storage) => {
        if (value === 'OrderManagementInfo') {
          //订单管理
          GetOrder((res) => {
            console.log('res', res.data);
            Promise.all(
              res.data
                // 排空
                .filter(it => it.item2 === null || it.item2.approvalStatus === 2)
                .filter(it => it.item1.startApprove === true)
                .map(it => {
                  return new Promise(resolve => {
                    GetUserInfo({
                      userId: it.item1.corpId,
                      fileds: null
                    }, (res) => {
                      it.item1.name = GetUserInfoFiled(res, 'name')
                      resolve(it)
                    })
                  })
                }))
              // 渲染值到前端
              .then(res => {
                this.setData({
                  OrderManagementInfo: compact(res).reverse()
                })
              })
          })
        }
        if (value === 'ConsumablesManagementInfo') {
          //耗材管理
          GetConsumableManagement((res) => {
            console.log('res', res.data);
            Promise.all(
              res.data
                // 排空
                .filter(it => it.item2 === null || it.item2.approvalStatus === 2)
                // 姓名处理
                .map(it => {
                  return new Promise(resolve => {
                    console.log('it', it);
                    GetUserInfo({
                      userId: it.item1.coperId,
                      fileds: null
                    }, (res) => {
                      it.item1.name = GetUserInfoFiled(res, 'name')
                      resolve(it)
                    })
                  })
                }))
              // 渲染值到前端
              .then(res => {
                this.setData({
                  ConsumablesManagementInfo: compact(res).reverse()
                })
              })
          })
        }
      }
    })
  },
  TapeOutPaymentsChange(value, items, e) {
    this.setData({
      SelectedValue: value ? value : this.data.SelectedValue
    })
    my.getStorage({
      key: 'userInfo',
      success: (storage) => {
        if (value === 'TapoutBusinessInfo') {
          //流片管理
          GetChipPayment((res) => {
            Promise.all(
              res.data
                // 排空
                .filter(it => it.item2 === null || it.item2.approvalStatus === 2)
                // 文件名称处理
                .map(it => {
                  it.item1['displayProofPayment'] = JSON.parse(it.item1.proofPayment)
                  it.item1['displayContractOrder'] = JSON.parse(it.item1.contractOrder)
                  return it
                })
                // 姓名处理
                .map(it => {
                  return new Promise(resolve => {
                    GetUserInfo({
                      userId: it.item1.corpId,
                      fileds: null
                    }, (res) => {
                      it.item1.name = GetUserInfoFiled(res, 'name')
                      resolve(it)
                    })
                  })
                }))
              // 渲染值到前端
              .then(res => {
                this.setData({
                  TapoutBusinessInfo: compact(res).reverse()
                })
              })
          })
        } else if (value === 'TapeoutIssuesContractsInfo') {
          //流片议题和合同
          GetTopicContract((res) => {
            Promise.all(
              res.data
                // 排空
                .filter(it => it.item2 === null || it.item2.approvalStatus === 2)
                // 文件名称处理
                .map(it => {
                  it.item1['displayAnnex'] = JSON.parse(it.item1.t_Annex)
                  it.item1['displayPicture_A'] = JSON.parse(it.item1.c_Picture_A)
                  it.item1['displayApprovalAnnex_A'] = JSON.parse(it.item1.c_ApprovalAnnex_A)
                  it.item1['displayPicture_B'] = JSON.parse(it.item1.c_Picture_B)
                  it.item1['displayApprovalAnnex_B'] = JSON.parse(it.item1.c_ApprovalAnnex_B)
                  return it
                })
                // 姓名处理
                .map(it => {
                  return new Promise(resolve => {
                    GetUserInfo({
                      userId: it.item1.t_CorpId,
                      fileds: null
                    }, (res) => {
                      it.item1.name = GetUserInfoFiled(res, 'name')
                      resolve(it)
                    })
                  })
                }))
              // 渲染值到前端
              .then(res => {
                this.setData({
                  TapeoutIssuesContractsInfo: compact(res).reverse()
                })
              })
          })
        }
      }
    })
  },
  ProjectManagementChange(value, items, e) {
    this.setData({
      SelectedValue: value ? value : this.data.SelectedValue
    })
    my.getStorage({
      key: 'userInfo',
      success: (storage) => {
        if (value === 'ProjectArchivingInfo') {
          //项目管理
          GetProjectManagement((res) => {
            Promise.all(
              res.data
                // 排空
                .filter(it => it.item2 === null || it.item2.approvalStatus === 2)
                // 文件名称处理
                .map(it => {
                  it.item1['DisplayInitiation'] = JSON.parse(it.item1.initiationReport)
                  it.item1['DisplayAnnual'] = JSON.parse(it.item1.annualReport)
                  it.item1['DisplayClosing'] = JSON.parse(it.item1.closingReport)
                  it.item1['DisplayAnnex'] = JSON.parse(it.item1.annex)
                  return it
                })
                // 姓名处理
                .map(it => {
                  return new Promise(resolve => {
                    GetUserInfo({
                      userId: it.item1.corpId,
                      fileds: null
                    }, (res) => {
                      it.item1.name = GetUserInfoFiled(res, 'name')
                      resolve(it)
                    })
                  })
                }))
              // 渲染值到前端
              .then(res => {
                this.setData({
                  ProjectArchivingInfo: compact(res).reverse()
                })
              })
          })
        }
      }
    })
  },
  FinancialManagementChange(value, items, e) {
    this.setData({
      SelectedValue: value ? value : this.data.SelectedValue
    })
    my.getStorage({
      key: 'userInfo',
      success: (storage) => {
        if (value === 'InvoicInfo') {
          //开票申请
          GetInvoicing((res) => {
            Promise.all(
              res.data
                .filter(it => it.item2 === null || it.item2.approvalStatus === 2)
                // 文件名称处理
                .map(it => {
                  it.item1['displayAnnex'] = JSON.parse(it.item1.annex)
                  return it
                })
                .map(it => {
                  return new Promise(r => {
                    GetUserInfo({
                      userId: it.item1.corpId,
                      fileds: null
                    }, (userInfo) => {
                      it.item1.name = GetUserInfoFiled(userInfo, 'name')
                      r(it)
                    })
                  })
                })
            ).then(res => {
              const promises = res.map(it => {
                it.item3 = []
                return Promise.all(JSON.parse(it.item1.associateOtherId)
                  .map(id => {
                    return new Promise((resolve) => {
                      GetContractManagementById(id, (evectionRes) => {
                        it.item3.push(evectionRes.data.item1)
                        resolve(it);
                      });
                    });
                  })).then(() => it)
              })
              return Promise.all(promises);
            }).then(DataRes => {
              this.setData({
                InvoicInfo: compact(DataRes).reverse()
              })
            })
          })
        } else if (value === 'IssueReceiptInfo') {
          //开收据申请
          GetIssueReceipts((res) => {
            Promise.all(
              res.data
                .filter(it => it.item2 === null || it.item2.approvalStatus === 2)
                // 文件名称处理
                .map(it => {
                  it.item1['displayAnnex'] = JSON.parse(it.item1.annex)
                  return it
                })
                .map(it => {
                  return new Promise(r => {
                    GetUserInfo({
                      userId: it.item1.corpId,
                      fileds: null
                    }, (userInfo) => {
                      it.item1.name = GetUserInfoFiled(userInfo, 'name')
                      r(it)
                    })
                  })
                })
            ).then(res => {
              const promises = res.map(it => {
                it.item3 = []
                return Promise.all(JSON.parse(it.item1.associateOtherId)
                  .map(id => {
                    return new Promise((resolve) => {
                      GetContractManagementById(id, (evectionRes) => {
                        it.item3.push(evectionRes.data.item1)
                        resolve(it);
                      });
                    });
                  })).then(() => it)
              })
              return Promise.all(promises);
            }).then(DataRes => {
              this.setData({
                IssueReceiptInfo: compact(DataRes).reverse()
              })
            })
          })

        } else if (value === 'ExpenseAccountInfo') {
          //报销申请
          GetReimbursement((res) => {
            Promise.all(
              res.data
                .filter(it => it.item2 === null || it.item2.approvalStatus === 2)
                // 文件名称处理
                .map(it => {
                  it.item1['displayAnnex'] = JSON.parse(it.item1.annex)
                  it.item1['displayTempTrip'] = JSON.parse(it.item1.tempTrip)
                  return it
                })
                .map(it => {
                  return new Promise(r => {
                    GetUserInfo({
                      userId: it.item1.corpId,
                      fileds: null
                    }, (userInfo) => {
                      it.item1.name = GetUserInfoFiled(userInfo, 'name')
                      r(it)
                    })
                  })
                })
            ).then(res => {
              const promises = res.map(it => {
                it.item3 = []
                return Promise.all(JSON.parse(it.item1.associateOtherId)
                  .map(id => {
                    return new Promise((resolve) => {
                      GetEvectionById(id, (evectionRes) => {
                        it.item3.push(evectionRes.data.item1)
                        resolve(it);
                      });
                    });
                  })).then(() => it)
              })
              return Promise.all(promises);
            }).then(DataRes => {
              this.setData({
                ExpenseAccountInfo: compact(DataRes).reverse()
              })
            })
          })
        } else if (value === 'PaymentFunctionInfo') {
          //付款申请
          GetPayment((res) => {
            Promise.all(
              res.data
                // 排空
                .filter(it => it.item2 === null || it.item2.approvalStatus === 2)
                .map(it => {
                  it.item1['displayAnnex'] = JSON.parse(it.item1.annex)
                  return it
                })
                .map(it => {
                  return new Promise(r => {
                    GetUserInfo({
                      userId: it.item1.corpId,
                      fileds: null
                    }, (userInfo) => {
                      it.item1.name = GetUserInfoFiled(userInfo, 'name')
                      r(it)
                    })
                  })
                })
            ).then(res => {
              const promises = res.map(it => {
                if (it.item1.associateOtherType === '关联合同') {
                  it.item3 = []
                  return Promise.all(JSON.parse(it.item1.associateOtherId)
                    .map(id => {
                      return new Promise((resolve) => {
                        GetContractManagementById(id, (evectionRes) => {
                          it.item3.push(evectionRes.data.item1)
                          resolve(it);
                        });
                      });
                    })).then(() => it)
                } else {
                  return Promise.resolve(it);
                }
              })
              return Promise.all(promises);
            }).then(DataRes => {
              this.setData({
                PaymentFunctionInfo: compact(DataRes).reverse()
              })
            })
          })
        }
      }
    })
  },

  IntegratedAdministrationChange(value, items, e) {
    this.setData({
      SelectedValue: value ? value : this.data.SelectedValue
    })
    my.getStorage({
      key: 'userInfo',
      success: (storage) => {
        if (value === 'PurchasRequisitInfo') {
          //采购申请
          GetPurchaseRequest((res) => {
            Promise.all(
              res.data
                // 排空
                .filter(it => it.item2 === null || it.item2.approvalStatus === 2)
                // 文件名称处理
                .map(it => {
                  it.item1['displayAnnex'] = JSON.parse(it.item1.annex)
                  return it
                })
                // 姓名处理
                .map(it => {
                  return new Promise(resolve => {
                    GetUserInfo({
                      userId: it.item1.corpId,
                      fileds: null
                    }, (res) => {
                      it.item1.name = GetUserInfoFiled(res, 'name')
                      resolve(it)
                    })
                  })
                }))
              // 渲染值到前端
              .then(res => {
                this.setData({
                  PurchasRequisitInfo: compact(res).reverse()
                })
              })
          })
        } else if (value === 'PurchasedConfirmationInfo') {
          //采购确认
          //可显示拒绝人姓名，暂时不用显示
          // GetProcurementConfirmation((res) => {  
          //   Promise.all(  
          //     res.data  
          //       .filter(it => it.item2 === null || it.item2.approvalStatus === 2)  
          //       .map(it => {  
          //         it.item1['displayAnnex'] = JSON.parse(it.item1.annex);  
          //         return it;  
          //       })  
          //       .map(it => {  
          //         return new Promise(r => {  
          //           GetUserInfo(  
          //             {  
          //               userId: it.item1.corpId,  
          //               fileds: null  
          //             }, (userInfo) => {  
          //               it.item1.name = GetUserInfoFiled(userInfo, 'name');  
          //               r(it);  
          //             }  
          //           );  
          //         });  
          //       })  
          //   ).then(processedItems => {  
          //     // 创建一个包含所有异步操作的 Promise 数组  
          //     const promises = processedItems.map(it => {  
          //       it.item3 = [];  
          //       return Promise.all(JSON.parse(it.item1.associateOtherId)  
          //         .map(id => {  
          //           return new Promise((resolve) => {  
          //             GetPurchaseRequestById(id, (evectionRes) => {  
          //               it.item3.push(...evectionRes.data.item1);  
          //               resolve(); // 不需要返回 it，因为它已经在外部作用域中  
          //             });  
          //           });  
          //         })  
          //       ).then(() => {  
          //         // 在这里，我们检查 item2 是否存在，如果存在则获取 approverId 的名字  
          //         if (!isEmpty(it.item2)) {  
          //           return new Promise(r => {  
          //             GetUserInfo(  
          //               {  
          //                 userId: it.item2.approverId,  
          //                 fileds: null  
          //               }, (userInfo) => {  
          //                 it.item2.approverIdName = GetUserInfoFiled(userInfo, 'name');  
          //                 r(it);  
          //               }  
          //             );  
          //           });  
          //         } else {  
          //           // 如果 item2 不存在，直接返回 it  
          //           return Promise.resolve(it);  
          //         }  
          //       });  
          //     });  
          //     // 使用 Promise.all 等待所有的异步操作完成，并获取结果  
          //     return Promise.all(promises);  
          //   }).then(DataRes => {  
          //     console.log('DataRes:', DataRes); // 现在 DataRes 应该包含处理后的数据  
          //     this.setData({  
          //       PurchasedConfirmationInfo: compact(DataRes).reverse()  
          //     });  
          //   }).catch(error => {  
          //     console.error('发生错误:', error); // 添加错误处理  
          //   });  
          // });
          GetProcurementConfirmation((res) => {
            Promise.all(
              res.data
                .filter(it => it.item2 === null || it.item2.approvalStatus === 2)
                // 文件名称处理
                .map(it => {
                  it.item1['displayAnnex'] = JSON.parse(it.item1.annex)
                  return it
                })
                .map(it => {
                  return new Promise(r => {
                    GetUserInfo({
                      userId: it.item1.corpId,
                      fileds: null
                    }, (userInfo) => {
                      it.item1.name = GetUserInfoFiled(userInfo, 'name')
                      r(it)
                    })
                  })
                })
            ).then(res => {
              const promises = res.map(it => {
                it.item3 = []
                return Promise.all(JSON.parse(it.item1.associateOtherId)
                  .map(id => {
                    return new Promise((resolve) => {
                      GetPurchaseRequestById(id, (evectionRes) => {
                        it.item3.push(evectionRes.data.item1)
                        resolve(it);
                      });
                    });
                  })).then(() => it)
              })
              return Promise.all(promises);
            }).then(DataRes => {
              this.setData({
                PurchasedConfirmationInfo: compact(DataRes).reverse()
              })
            })
          })
        } else if (value === 'SealInfo') {
          //用印申请
          GetUseSeal((res) => {
            Promise.all(
              res.data
                // 排空
                .filter(it => it.item2 === null || it.item2.approvalStatus === 2)
                // 姓名处理
                .map(it => {
                  return new Promise(resolve => {
                    GetUserInfo({
                      userId: it.item1.corpId,
                      fileds: null
                    }, (res) => {
                      it.item1.name = GetUserInfoFiled(res, 'name')
                      resolve(it)
                    })
                  })
                }))
              // 渲染值到前端
              .then(res => {
                this.setData({
                  SealInfo: compact(res).reverse()
                })
              })
          })
        } else if (value === 'TopicInfo') {
          //议题申请
          new Promise(resolve => {
            GetTopic(res => resolve(res.data.map(it => {
              if (it.item1.corpId === storage.data.result.userid) {
                it.item1['displayAnnex'] = JSON.parse(it.item1.annex)
                return it
              }
            })))
          }).then(res => {
            return res
              .filter(it => it.item2 !== null && it.item2.length > 0)
          }).then(res => {
            return res.map(it => {
              it.item3 = []
              it.item2.forEach(approval => {
                if (approval.approvalStatus >= 0) {
                  it.item3.push({
                    msg: approval.approveMsg,
                    approver: approval.approverId,
                    show: approval.approvalStatus !== 0
                  })
                }
              });
              return it
            })
          }).then(res => {
            const ids = []
            res.forEach(it => it.item3.forEach(i => {
              ids.push(i.approver)
            }))
            return Promise.all([
              Promise.resolve(res),
              ...ids.map(id => {
                return GetUserNameById(id)
              })
            ])
          }).then(res => {
            const data = res[0]
            const names = res.slice(1)

            return data.map(it => {
              it.item3.map(i3 => {
                names.forEach(name => {
                  if (name.id === i3.approver) {
                    i3.name = name.name
                  }
                })
                return i3
              })
              return it
            })
          }).then(res => {
            this.setData({
              TopicInfo: res.reverse()
            })
          })
          // //议题申请
          // GetTopic((res) => {
          //   console.log('res', res);
          //   Promise.all(
          //     res.data
          //       .filter(it => it.item2 !== null && it.item2.length > 0)
          //       .map(it => {
          //         it.item3 = []
          //         it.item2.forEach(approval => {
          //           if (approval.approvalStatus >= 0) {
          //             it.item3.push({ msg: approval.approveMsg, approver: approval.approverId })
          //           }
          //         });
          //         return it
          //       })
          //       // .map(it => {
          //       //   it.currentApprove = null
          //       //   it.item2.forEach(approval => {
          //       //     if (approval.approvalStatus === 0 && it.currentApprove === null)
          //       //       it.currentApprove = approval
          //       //   })
          //       //   return it
          //       // })
          //       // .filter(it => it.currentApprove !== null)
          //       // // 排空
          //       // .filter(it => !isEmpty(it.item2))
          //       // // 删除退回
          //       // .filter(it => it.item2.approvalStatus !== 2)
          //       // 匹配审核人
          //       // .filter(it => it.currentApprove.approverId === storage.data.result.userid)
          //       // 文件名称处理
          //       .map(it => {
          //         it.item1['displayAnnex'] = JSON.parse(it.item1.annex)
          //         return it
          //       })
          //       // 姓名处理
          //       .map(it => {
          //         return new Promise(resolve => {
          //           GetUserInfo(
          //             {
          //               userId: it.item1.corpId,
          //               fileds: null
          //             }, (res) => {
          //               console.log('res', res);
          //               it.item1.name = GetUserInfoFiled(res, 'name')
          //               resolve(it)
          //             }
          //           )
          //         })
          //       }))
          //     // 渲染值到前端
          //     .then(res => {
          //       console.log('LOG DATA', res);
          //       this.setData({
          //         TopicInfo: compact(res).reverse()
          //       })
          //     })
          // })
          // new Promise((resolve) => {
          //   GetTopic((res) => {
          //     resolve(res.data.filter(s => (s.item2 === null || s.item2.approvalStatus === 2)))
          //   })
          // })
          //   .then((res) => {
          //     return Promise.all(res.map(it => new Promise((resolve) => {
          //       GetApproveLog(it.item1.id, (r) => {
          //         it.item3 = r.data
          //         it.item1['displayAnnex'] = JSON.parse(it.item1.annex)
          //         resolve(it)
          //       })
          //     })))
          //   })
          //   .then(res => {
          //     return new Promise((resolve) => {
          //       GetUserInfo({ userId: storage.data.result.userid, fileds: null }, (r) => {
          //         const name = GetUserInfoFiled(r, 'name')
          //         resolve(res.map(it => {
          //           it.item1.name = name
          //           return it
          //         }))
          //       })
          //     })
          //   })
          //   .then((res) => {
          //     console.log('res', res);
          //     const tmp = new Set()
          //     res.forEach(i => {
          //       tmp.add(...i.item3.map(it => it.approverId))
          //     })
          //     const ids = Array.from(tmp)
          //     return Promise.all(ids.map(id =>
          //       new Promise(resolve => {
          //         GetUserInfo({ userId: id, fileds: null }, (r) => {
          //           const name = GetUserInfoFiled(r, 'name');
          //           resolve({ id, name })
          //         })
          //       })
          //     )).then(r => {
          //       console.log('rrrrr', r);
          //       return res.map(it => {
          //         it.item3 = it.item3.map(approveInfo => {
          //           console.log('approveInfo', approveInfo);
          //           approveInfo.name = r.find(name => name.id === approveInfo.approverId).name
          //           return approveInfo
          //         })
          //         return it
          //       })
          //     })
          //   })
          //   .then(res => {
          //     // console.log('res', res);
          //     this.setData({
          //       TopicInfo: res
          //     })
          //   })
        } else if (value === 'MeetMinutesInfo') {
          //会议纪要
          GetMeetingMinutes((res) => {
            Promise.all(
              res.data
                .filter(it => it.item2 === null || it.item2.approvalStatus === 2)
                // 文件名称处理
                .map(it => {
                  it.item1['displayMeetingAttachments'] = JSON.parse(it.item1.meetingAttachments)
                  it.item1['displayMeetingMinutes'] = JSON.parse(it.item1.meetingMinutes)
                  it.item1['displayTempTopic'] = JSON.parse(it.item1.tempTopic)
                  return it
                })
                .map(it => {
                  return new Promise(r => {
                    GetUserInfo({
                      userId: it.item1.corpId,
                      fileds: null
                    }, (userInfo) => {
                      it.item1.name = GetUserInfoFiled(userInfo, 'name')
                      r(it)
                    })
                  })
                })
            ).then(res => {
              const promises = res.map(it => {
                it.item3 = []
                return Promise.all(JSON.parse(it.item1.associateOtherId)
                  .map(id => {
                    return new Promise((resolve) => {
                      GetTopicById(id, (evectionRes) => {
                        it.item3.push(evectionRes.data.item1)
                        resolve(it);
                      });
                    });
                  })).then(() => it)
              })
              return Promise.all(promises);
            }).then(DataRes => {
              this.setData({
                MeetMinutesInfo: compact(DataRes).reverse()
              })
            })
          })
        } else if (value === 'ContractInfo') {
          //合同管理
          GetContractManagement((res) => {
            Promise.all(
              res.data
                .filter(it => it.item2 === null || it.item2.approvalStatus === 2)
                // 文件名称处理
                .map(it => {
                  it.item1['displayPicture'] = JSON.parse(it.item1.picture)
                  it.item1['displayApprovalAnnex'] = JSON.parse(it.item1.approvalAnnex)
                  return it
                })
                .map(it => {
                  return new Promise(r => {
                    GetUserInfo({
                      userId: it.item1.corpId,
                      fileds: null
                    }, (userInfo) => {
                      it.item1.name = GetUserInfoFiled(userInfo, 'name')
                      r(it)
                    })
                  })
                })
            ).then(res => {
              const promises = res.map(it => {
                it.item3 = []
                return Promise.all(JSON.parse(it.item1.associateOtherId)
                  .map(id => {
                    return new Promise((resolve) => {
                      GetTopicById(id, (evectionRes) => {
                        it.item3.push(evectionRes.data.item1)
                        resolve(it);
                      });
                    });
                  })).then(() => it)
              })
              return Promise.all(promises);
            }).then(DataRes => {
              this.setData({
                ContractInfo: compact(DataRes).reverse()
              })
            })
          })
        }
        if (value === 'SalaryInfo') {
          //薪资审批
          GetSalaryInfo((res) => {
            Promise.all(
              res.data
                // 排空
                .filter(it => it.item2 === null || it.item2.approvalStatus === 2)
                // 文件名称处理
                .map(it => {
                  it.item1['displayAnnex'] = JSON.parse(it.item1.annex)
                  return it
                })
                // 姓名处理
                .map(it => {
                  return new Promise(resolve => {
                    GetUserInfo({
                      userId: it.item1.corpId,
                      fileds: null
                    }, (res) => {
                      it.item1.name = GetUserInfoFiled(res, 'name')
                      resolve(it)
                    })
                  })
                }))
              // 渲染值到前端
              .then(res => {
                this.setData({
                  SalaryInfo: compact(res).reverse()
                })
              })
          })
        }
      }
    })
  },

  BasicApplicationChange(value, items, e) {
    this.setData({
      SelectedValue: value ? value : this.data.SelectedValue
    })
    my.getStorage({
      key: 'userInfo',
      success: (storage) => {
        if (value === 'LeaveInfo') {
          //请假申请
          GetLeave((res) => {
            Promise.all(
              res.data
                // 排空
                .filter(it => it.item2 === null || it.item2.approvalStatus === 2)
                // 文件名称处理
                .map(it => {
                  it.item1['displayAnnex'] = JSON.parse(it.item1.annex)
                  return it
                })
                // 姓名处理
                .map(it => {
                  return new Promise(resolve => {
                    GetUserInfo({
                      userId: it.item1.corpId,
                      fileds: null
                    }, (res) => {
                      it.item1.name = GetUserInfoFiled(res, 'name')
                      resolve(it)
                    })
                  })
                }))
              // 渲染值到前端
              .then(res => {
                this.setData({
                  LeaveInfo: compact(res).reverse()
                })
              })
          })
        } else if (value === 'EvectionInfo') {
          //出差申请
          GetEvection((res) => {
            Promise.all(
              res.data
                // 排空
                .filter(it => it.item2 === null || it.item2.approvalStatus === 2)
                // 文件名称处理
                .map(it => {
                  it.item1['displayAnnex'] = JSON.parse(it.item1.annex)
                  it.item1['displayAddJourney'] = JSON.parse(it.item1.addJourney)
                  return it
                })
                // 姓名处理
                .map(it => {
                  return new Promise(resolve => {
                    GetUserInfo({
                      userId: it.item1.corpId,
                      fileds: null
                    }, (res) => {
                      it.item1.name = GetUserInfoFiled(res, 'name')
                      resolve(it)
                    })
                  })
                }))
              // 渲染值到前端
              .then(res => {
                this.setData({
                  EvectionInfo: compact(res).reverse()
                })
              })
          })
        }
      }
    })
  },
  show(e) {
    const item = e.target.dataset.item
    this.setData({
      [item]: !this.data[item]
    })
  },
  onLoad() {
    //获取请假数据
    my.getStorage({
      key: 'userInfo',
      success: (res) => {
        const id = res.data.result.userid
        this.setData({
          CorpId: id
        })
      }
    })
  },
  CheckPictures(e) {
    const item = e.currentTarget.dataset.item
    dd.previewFileInDingTalk({
      spaceId: item.spaceId,
      fileName: item.fileName,
      corpId: CORPID,
      fileSize: item.fileSize,
      fileType: item.fileType,
      fileId: item.fileId,
    });
  },


  // //图片下载函数
  // DownImg(e) {
  //   const imgNames = e.currentTarget.dataset.annex.split(',');
  //   if (isEmpty(e.currentTarget.dataset.annex)) {
  //     my.alert({ content: '无附件图片！' })
  //   } else {
  //     Promise.all(imgNames.map(imgName =>
  //       new Promise((resolve) => {
  //         GetInfoPicture(imgName, (res) => {
  //           resolve(res.filePath)
  //         })
  //       })
  //     )).then(res => {
  //       GetPreviewImage(res)
  //     })
  //   }
  // },
  // //图片下载函数
  // DownImgPicture(e) {
  //   const imgNames = e.currentTarget.dataset.picture.split(',');
  //   if (isEmpty(e.currentTarget.dataset.picture)) {
  //     my.alert({ content: '无附件图片！' })
  //   } else {
  //     Promise.all(imgNames.map(imgName =>
  //       new Promise((resolve) => {
  //         GetInfoPicture(imgName, (res) => {
  //           resolve(res.filePath)
  //         })
  //       })
  //     )).then(res => {
  //       GetPreviewImage(res)
  //     })
  //   }
  // },
  // //图片下载函数
  // DownImgRes(e) {
  //   const imgNames = e.currentTarget.dataset.resultReport.split(',');
  //   if (isEmpty(e.currentTarget.dataset.resultReport)) {
  //     my.alert({ content: '无附件图片！' })
  //   } else {
  //     Promise.all(imgNames.map(imgName =>
  //       new Promise((resolve) => {
  //         GetInfoPicture(imgName, (res) => {
  //           resolve(res.filePath)
  //         })
  //       })
  //     )).then(res => {
  //       GetPreviewImage(res)
  //     })
  //   }
  // },
  // //图片下载函数
  // DownImgMet(e) {
  //   const imgNames = e.currentTarget.dataset.meetingAttachments.split(',');
  //   if (isEmpty(e.currentTarget.dataset.meetingAttachments)) {
  //     my.alert({ content: '无附件图片！' })
  //   } else {
  //     Promise.all(imgNames.map(imgName =>
  //       new Promise((resolve) => {
  //         GetInfoPicture(imgName, (res) => {
  //           resolve(res.filePath)
  //         })
  //       })
  //     )).then(res => {
  //       GetPreviewImage(res)
  //     })
  //   }
  // },
  // DownImgProofPayment(e) {
  //   const imgNames = e.currentTarget.dataset.proofPayment.split(',');
  //   if (isEmpty(e.currentTarget.dataset.proofPayment)) {
  //     my.alert({ content: '无附件图片！' })
  //   } else {
  //     Promise.all(imgNames.map(imgName =>
  //       new Promise((resolve) => {
  //         GetInfoPicture(imgName, (res) => {
  //           resolve(res.filePath)
  //         })
  //       })
  //     )).then(res => {
  //       GetPreviewImage(res)
  //     })
  //   }
  // },
});